/**
 * Class: Actor
 *
 * Purpose: 
 *
 * Created: Jan 26, 2010 @ 5:38:53 PM
 * @author Ken Scott
 */
package org.openfantasia.ps.actor;

import org.openfantasia.ps.modifier.Behavior;
import org.openfantasia.ps.modifier.behaviors.BehaviorManager;
import org.openfantasia.ps.particle.Particle;
import org.openfantasia.time.TimeKeeper;
import org.openfantasia.ui.PFrame;
import org.openfantasia.util.listener.Event;
import org.openfantasia.util.listener.Listener;
import org.openfantasia.util.listener.ListenerManager;

public abstract class Actor implements Listener, TimeKeeper {

	protected PFrame frame;

	protected ListenerManager listeners = new ListenerManager();

	protected BehaviorManager behaviors = new BehaviorManager();


	protected Actor() {
	}


	public Actor(PFrame frame) {
		this.frame = frame;
		setup();
	}


	public Actor(Actor that) {
		copy(that);
	}


	public void copy(Actor that) {
		this.frame = that.frame;
		this.behaviors = new BehaviorManager(that.behaviors);
		this.listeners = new ListenerManager();
	}


	public void setup() {
	}


	public void draw(Particle particle) {
	}


	public PFrame getFrame() {
		return frame;
	}


	public void setFrame(PFrame frame) {
		this.frame = frame;
	}


	public double getTime() {
		return frame.getTime();
	}


	public void addListener(String channel, Listener listener) {
		listeners.add(channel, listener);
	}


	public void removeListener(String channel, Listener listener) {
		listeners.remove(channel, listener);
	}


	public void receive(Event event) {
		listeners.send(event.getChannel(), event);
	}


	public void addBehavior(String name, Behavior bhv) {
		behaviors.add(name, bhv);
	}


	public void removeBehavior(String name, Behavior bhv) {
		behaviors.remove(name, bhv);
	}


	public Object getBehaviorValue(String name, Particle particle, double time, Object param) {
		return behaviors.getBehaviorValue(name, particle, time, param);
	}
}
